namespace InventoryManagement
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Data.SqlClient;
	using System.Text;
	
	
	public class Detail_Printer : BaseTable
	{
		
		#region Static SQL String Members
		/// <remarks>This field represents the full SELECT string for the table Detail Printer, with the WHERE clause.</remarks>
		internal static string _SQL_Select = "SELECT [ID], [ID_DataCabang], [ID_Printer], [Jumlah] FROM [dbo].[Detail Printer] WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the full SELECT string for the table Detail Printer, with the WHERE clause.</remarks>
		internal static string _SQL_SelectByParam = @"SELECT [ID], [ID_DataCabang], [ID_Printer], [Jumlah] FROM [dbo].[Detail Printer] WHERE isnull(convert(varchar(36),[ID]),'true')=isnull(convert(varchar(36),@ID),isnull(convert(varchar(36),[ID]),'true')) AND isnull(convert(varchar(36),[ID_DataCabang]),'true')=isnull(convert(varchar(36),@ID_DataCabang),isnull(convert(varchar(36),[ID_DataCabang]),'true')) AND isnull(convert(varchar(36),[ID_Printer]),'true')=isnull(convert(varchar(36),@ID_Printer),isnull(convert(varchar(36),[ID_Printer]),'true')) AND isnull(convert(varchar,[Jumlah]),'true')=isnull(convert(varchar,@Jumlah),isnull(convert(varchar,[Jumlah]),'true')) ";
		
		/// <remarks>This field represents the full INSERT INTO string for the table Detail Printer.</remarks>
		internal static string _SQL_Insert = "INSERT INTO [dbo].[Detail Printer] ([ID], [ID_DataCabang], [ID_Printer], [Jumlah]) VALUES(@ID, @ID_DataCabang, @ID_Printer, @Jumlah) ";
		
		/// <remarks>This field represents the full UPDATE string for the table Detail Printer, with the WHERE clause.</remarks>
		internal static string _SQL_Update = "UPDATE [dbo].[Detail Printer] SET [ID] = @ID, [ID_DataCabang] = @ID_DataCabang, [ID_Printer] = @ID_Printer, [Jumlah] = @Jumlah WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the DELETE string for the table Detail Printer, with the WHERE clause.</remarks>
		internal static string _SQL_Delete = "DELETE FROM [dbo].[Detail Printer] WHERE [ID]=@ID ";
		#endregion
		
		#region Tables Members
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID;
		
		[DisplayName("ID")]
		[Category("Primary Key")]
		public System.Nullable<System.Guid> ID
		{
			get
			{
				try
				{
					return _ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID", err);
				}
			}
			set
			{
				try
				{
					_ID = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID", err);
				}
			}
		}
		
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID_DataCabang;
		
		[DisplayName("ID_Data Cabang")]
		[Category("Foreign Key")]
		public System.Nullable<System.Guid> ID_DataCabang
		{
			get
			{
				try
				{
					return _ID_DataCabang;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_DataCabang", err);
				}
			}
			set
			{
				try
				{
					_ID_DataCabang = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_DataCabang", err);
				}
			}
		}
		
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID_Printer;
		
		[DisplayName("ID_Printer")]
		[Category("Foreign Key")]
		public System.Nullable<System.Guid> ID_Printer
		{
			get
			{
				try
				{
					return _ID_Printer;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_Printer", err);
				}
			}
			set
			{
				try
				{
					_ID_Printer = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_Printer", err);
				}
			}
		}
		
		/// <remarks>SQL Type:int - </remarks>
		private System.Nullable<int> _Jumlah;
		
		[DisplayName("Jumlah")]
		[Category("Column")]
		public System.Nullable<int> Jumlah
		{
			get
			{
				try
				{
					return _Jumlah;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Jumlah", err);
				}
			}
			set
			{
				try
				{
					_Jumlah = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Jumlah", err);
				}
			}
		}
		#endregion
		
		#region Related Objects
		/// <remarks>Represents the foreign key object</remarks>
		private Data_Cabang _ID_DataCabang_Data_Cabang;
		
		[Description("Represents the foreign key object of the type Data_Cabang")]
		public Data_Cabang ID_DataCabang_Data_Cabang
		{
			get
			{
				try
				{
					return _ID_DataCabang_Data_Cabang;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_DataCabang_Data_Cabang", err);
				}
			}
			set
			{
				try
				{
					_ID_DataCabang_Data_Cabang = value;
					_ID_DataCabang = _ID_DataCabang_Data_Cabang.ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_DataCabang_Data_Cabang", err);
				}
			}
		}
		
		/// <remarks>Represents the foreign key object</remarks>
		private Printer _ID_Printer_Printer;
		
		[Description("Represents the foreign key object of the type Printer")]
		public Printer ID_Printer_Printer
		{
			get
			{
				try
				{
					return _ID_Printer_Printer;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_Printer_Printer", err);
				}
			}
			set
			{
				try
				{
					_ID_Printer_Printer = value;
					_ID_Printer = _ID_Printer_Printer.ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_Printer_Printer", err);
				}
			}
		}
		#endregion
		
		#region Public Methods
		public void Select()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Detail_Printer._SQL_Select;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataReader rs = Com.ExecuteReader();
				while(rs.Read())
				{
					AddFromRecordSet(rs);
				}
				rs.Close();
				Conn.Close();
				rs.Dispose();
				Com.Dispose();
				Conn.Dispose();
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public System.Data.DataTable SelectByParam()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Detail_Printer._SQL_SelectByParam;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataAdapter objDataAdapter = new SqlDataAdapter(Com);
				DataTable objDataTable = new DataTable();
				objDataAdapter.Fill(objDataTable);
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return objDataTable;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Insert()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Detail_Printer._SQL_Insert;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Update()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Detail_Printer._SQL_Update;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Delete()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Detail_Printer._SQL_Delete;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public string[] GetSqlCommandStrings()
		{
			try
			{
				string[] CommStr = new string[4];
				CommStr[0] = "SELECT [ID], [ID_DataCabang], [ID_Printer], [Jumlah] FROM [dbo].[Detail Printer] WHERE [ID] = " + _ID + "";
				CommStr[1] = "INSERT INTO [dbo].[Detail Printer] ([ID], [ID_DataCabang], [ID_Printer], [Jumlah]) VALUES(" + _ID + ", " + _ID_DataCabang + ", " + _ID_Printer + ", " + _Jumlah + ")";
				CommStr[2] = "UPDATE [dbo].[Detail Printer] SET [ID_DataCabang] = " + _ID_DataCabang + " ,[ID_Printer] = " + _ID_Printer + " ,[Jumlah] = " + _Jumlah + " WHERE [ID] = " + _ID + "";
				CommStr[3] = "DELETE FROM [dbo].[Detail Printer] WHERE [ID] = " + _ID + "";
				return CommStr;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		#endregion
		
		#region Private Methods
		private void AddFromRecordSet(SqlDataReader rs)
		{
			try
			{
				// if value from the recordset, to the ID field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID")) == false))
				{
					ID = rs.GetGuid(rs.GetOrdinal("ID"));
				}
				// if value from the recordset, to the ID_DataCabang field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID_DataCabang")) == false))
				{
					ID_DataCabang = rs.GetGuid(rs.GetOrdinal("ID_DataCabang"));
				}
				// if value from the recordset, to the ID_Printer field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID_Printer")) == false))
				{
					ID_Printer = rs.GetGuid(rs.GetOrdinal("ID_Printer"));
				}
				// if value from the recordset, to the Jumlah field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Jumlah")) == false))
				{
					Jumlah = rs.GetInt32(rs.GetOrdinal("Jumlah"));
				}
			}
			catch (SqlException sqlExc)
			{
				throw sqlExc;
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		
		private SqlParameter[] GetSqlParameters()
		{
			List<SqlParameter> SqlParmColl = new List<SqlParameter>();
			try
			{
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID", ID, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID_DataCabang", ID_DataCabang, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID_Printer", ID_Printer, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Jumlah", Jumlah, SqlDbType.Int));
				return SqlParmColl.ToArray();
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		#endregion
	}
	
	public class Detail_PrinterCollection : System.Collections.CollectionBase
	{
		
		[Description("Adds a new Detail_Printer to the collection.")]
		public int Add(Detail_Printer item)
		{
			int newindex = List.Add(item);
			return newindex;
		}
		
		[Description("Removes a Detail_Printer from the collection.")]
		public void Remove(Detail_Printer item)
		{
			List.Remove(item);
		}
		
		[Description("Inserts an Detail_Printer into the collection at the specified index.")]
		public void Insert(int index, Detail_Printer item)
		{
			List.Insert(index, item);
		}
		
		[Description("Returns the index value of the Detail_Printer class in the collection.")]
		public int IndexOf(Detail_Printer item)
		{
			return List.IndexOf(item);
		}
		
		[Description("Returns true if the Detail_Printer class is present in the collection.")]
		public bool Contains(Detail_Printer item)
		{
			return List.Contains(item);
		}
	}
	
	public enum Detail_Printer_Fields
	{
		
		ID,
		
		ID_DataCabang,
		
		ID_Printer,
		
		Jumlah,
	}
}
